import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { TableC, SecondHeaderC } from '../../../../../comps';
import YieldTrend from './yieldTrend'; //收益率趋势
class YieldTrend2 extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }
  componentDidMount() {
    if (this.props.searchData && this.props.searchData.portfolioCode) {
      // 获取区间收益率数据
      this.getyieldOrgLevelData({
        portfolioCode: this.props.searchData?.portfolioCode,
        dataDate: this.props.searchData?.endDate,
      });
    }
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (JSON.stringify(nextProps.searchData) !== JSON.stringify(this.props.searchData)) {
      // 获取区间收益率数据
      this.getyieldOrgLevelData({
        portfolioCode: nextProps.searchData?.portfolioCode,
        dataDate: nextProps.searchData?.endDate,
      });
    }
  }

  getyieldOrgLevelData(searchProps) {
    this.props.dispatch({
      type: 'yieldPerformanceInProM/yieldOrgLevel',
      payload: searchProps,
    });
  }

  render() {
    const {
      loading,
      yieldPerformanceInProM: { columns, yieldOrgLevelData2 },
      colorType,
    } = this.props;

    return (
      <>
        <div style={{ marginBottom: '20px' }}>
          <SecondHeaderC title='收益率趋势' colorType={colorType} />
          <TableC
            columns={columns}
            dataSource={yieldOrgLevelData2}
            rowKey='oneMonth'
            loading={loading.effects['yieldPerformanceInProM/yieldOrgLevel'] == true}
            hidePage={true}
            colorType={colorType}
          />
        </div>
        <YieldTrend {...this.props} yieldTrendType={2} />
      </>
    );
  }
}
export default connect(({ yieldPerformanceInProM, loading }) => ({ yieldPerformanceInProM, loading }))(YieldTrend2);
